package org.jeecg.modules.platformMasterEndPoint.controller;

import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.platformMasterEndPoint.entity.JxAfterSalesDo;
import org.jeecg.modules.platformMasterEndPoint.mapper.JxAfterSalesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/jx/jxOrderManage")
public class JxOrderManageController {


    @Autowired
    private JxAfterSalesMapper jxAfterSalesMapper;

    /**
     * 接口
     * @param request
     * @param requestBody
     * @return
     */
    @PutMapping("/handleAfterSale")
    public Result<?> handleAfterSale(
            HttpServletRequest request,
            @RequestBody()JSONObject requestBody) {

        String afterSaleId = requestBody.getString("afterSaleId");
        String state = requestBody.getString("state");
        String comments = requestBody.getString("comments");

        JxAfterSalesDo afterSalesDo = new JxAfterSalesDo();
        afterSalesDo.setId(afterSaleId);
        afterSalesDo.setState(state);
        afterSalesDo.setComments(comments);

        int updateCount = jxAfterSalesMapper.updateById(afterSalesDo);

        if (updateCount == 1) {
            return Result.ok("售后工单处理完成，状态更新成功");
        } else {
            return Result.error("售后工单处理失败，请联系后台技术人员进行处理");
        }
    }
}
